package com.atguigu.cloud.sevice.Impl;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.alibaba.druid.sql.builder.UpdateBuilder;
import com.atguigu.cloud.entities.Collect;
import com.atguigu.cloud.sevice.CollectService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import com.atguigu.cloud.mapper.CollectMapper;

import java.util.List;

/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.sevice.Impl
 * @className: collectServiceImpl
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 17:48
 * @version: 1.0
 */
@Service
//收藏夹实例
public class CollectServiceImpl implements CollectService {
    @Resource
    CollectMapper collectMapper;
    @Override
    //根据id获取收藏夹
    public Collect getById(Integer id) {
        QueryWrapper<Collect> queryWrapper= new QueryWrapper<>();
        queryWrapper.eq("id",id);
        Collect collect = collectMapper.selectOne(queryWrapper);
        return collect;
    }

    @Override
    public List<Collect> getAll() {
        QueryWrapper<Collect> queryWrapper= new QueryWrapper<>();
        List<Collect> list_collect = collectMapper.selectList(queryWrapper);
        return list_collect;
    }

    @Override
    public int add(Collect collect) {
        collectMapper.insert(collect);
        return collect.getId();
    }

    @Override
    public int delete(Integer id) {
        QueryWrapper<Collect> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        int result_id =collectMapper.delete(queryWrapper);
        return result_id;
    }

    @Override
    public int update(Collect collect) {
        int id = collect.getId();
        UpdateWrapper<Collect> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        collectMapper.update(collect,updateWrapper);
        return id;
    }

}
